﻿//-------------------------------------------------------------------
//	Copyright (c) 2010-2014  Zhirnov Andrey
//	This file is part of the "UX Standard Lib" project.
//	See copyright notice in "UX_STL_Ext.h".
//-------------------------------------------------------------------

#ifndef _UXS_THREAD_MANAGER_H
#define _UXS_THREAD_MANAGER_H

#pragma once

#include "IThreadOp.h"
#include "CThread.h"

namespace UX_STL
{
namespace UXTypesExt
{

	//
	// Thread Manager
	//

	class CThreadManager
	{
	public:
		typedef array< IThread *, TFastCopyStrategy< IThread *> >	thread_array_t;

	private:
		thread_array_t		_aThreads;
		ReadWriteSync		_sLockThreads;
		uint				_uThreadCounter;

	public:
		CThreadManager ();
		~CThreadManager ();

		bool PushOp (e_thread::type eType, IThreadOp *pOp, bool bHightPriority = false, bool bExceptCurrent = true);
		bool PushOpToAll (e_thread::type eType, IThreadOpC *pOp, bool bHightPriority = false, bool bExceptCurrent = true);
		
		void AddThread (IThread *pThread);
		void RemoveThread (IThread *pThread);
		void DestroyAll ();
		bool PauseAll ();
		bool ResumeAll ();

		usize GetCount ();
		bool  IsCurProcessThread ();
	};

//-------------------------------------------------------------------

}	// UXTypesExt
}	// UX_STL

#endif	// _UXS_THREAD_MANAGER_H